<?php
namespace App\Lib\WeApp\Api;

class WxLink extends BaseApi{

    public function genWxUrllink($path, $query){
        $url = ApiUrl::LINK_GEN_WX_A_URL_LINK;
        $param = array(
            'path'=>$path,
            'query'=>$query,
            'expire_type'=>1,
            'expire_interval' => 30
        );
        $data = $this->sendRequestWithToken($url,$param);
        if($data && $data['errcode'] == 0 && $data['url_link']){
            return $data['url_link'];
        }else{
            _logger_(__file__, __line__, $data);
            return null;
        }
    }

    public function genWxShortlink($page_url, $page_title, $is_mp = false, $is_permanent = false ){
        $url = ApiUrl::LINK_GEN_WX_A_SHORT_LINK;
        $param = array(
            'page_url'=>$page_url,
            'page_title'=>$page_title,
            'is_permanent'=>$is_permanent,
        );
        $data = $this->sendRequestWithToken($url,$param);
        if($data && $data['errcode'] == 0 && $data['link']){
            if($is_mp){
                $link_arr = explode('/', $data['link']);
                return 'mp://'.end($link_arr);
            }else{
                return $data['link'];
            }
        }else{
            _logger_(__file__, __line__, $data);
            return null;
        }
    }

}
